//
//  BookmarksDataSource.m
//  Autobusim
//
//  Created by Hezi Cohen on 12/8/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "BookmarksDataSource.h"


@implementation BookmarksDataSource

@synthesize bookmarks;

- (id)initWithDelegate:(id)aDelegate {
    [super init];
    delegate = aDelegate;   
	[self loadBookmarks];
    return self;
}

- (void)loadBookmarks {
	bookmarks = (NSMutableArray*)[[NSUserDefaults standardUserDefaults] objectForKey:@"bookmarks"];
	if(bookmarks == nil)
		bookmarks = [[NSMutableArray alloc]init];
}

- (void)saveBookmarks {
	[[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:@"bookmarks"];
    [[NSUserDefaults standardUserDefaults] synchronize];	
}

- (void)dealloc {
	[self saveBookmarks];
	[super dealloc];
}

#pragma mark TableViewDataSource Methods:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
	return @"מועדפים";
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
	return [bookmarks count];
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
	
	// Configure the cell
	[cell setUserInteractionEnabled:NO];
	[cell setText: (NSString*)[bookmarks objectAtIndex:indexPath.row]];
	
	return cell;
}	

/*
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 }
 */

/*
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 }
 if (editingStyle == UITableViewCellEditingStyleInsert) {
 }
 }
 */

/*
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */



@end
